package com.CyclicBarrier;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeoutException;

/**
 * Created by apple on 17/9/29.
 */
public class TaskThread extends Thread {
    private CyclicBarrier cyc;

    public TaskThread(CyclicBarrier cyc) {
        this.cyc = cyc;
    }

    @Override
    public void run() {
        System.out.println("线程 " + Thread.currentThread().getName());

        try{
            Thread.sleep(5000);
            System.out.println("线程" + Thread.currentThread().getName() + "完毕");
            cyc.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName() + "所有线程完毕");
    }
}
